<template>
  <view v-if="visible" class="modal-overlay" @click="handleOverlayClick">
    <view class="modal-content" @click.stop>
      <!-- 标题栏 -->
      <view class="modal-header">
        <text class="modal-title">{{ title }}</text>
        <view class="modal-close" @click="handleClose">
          <text class="close-icon">×</text>
        </view>
      </view>
      
      <!-- 内容区域 -->
      <view class="modal-body">
        <text class="modal-text">{{ content }}</text>
      </view>
      
      <!-- 按钮区域 -->
      <view class="modal-footer">
        <view v-if="showCancel" class="modal-btn cancel-btn" @click="handleCancel">
          <text class="btn-text">{{ cancelText }}</text>
        </view>
        <view class="modal-btn confirm-btn" @click="handleConfirm">
          <text class="btn-text">{{ confirmText }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  title: {
    type: String,
    default: ''
  },
  content: {
    type: String,
    default: ''
  },
  showCancel: {
    type: Boolean,
    default: true
  },
  cancelText: {
    type: String,
    default: '取消'
  },
  confirmText: {
    type: String,
    default: '确定'
  }
})

const emit = defineEmits(['close', 'cancel', 'confirm'])

const handleOverlayClick = () => {
  emit('close')
}

const handleClose = () => {
  emit('close')
}

const handleCancel = () => {
  emit('cancel')
}

const handleConfirm = () => {
  emit('confirm')
}
</script>

<style lang="scss" scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-content {
  background-color: white;
  border-radius: 12px;
  width: 80%;
  max-width: 320px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #f0f0f0;
}

.modal-title {
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.modal-close {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.close-icon {
  font-size: 18px;
  color: #666;
  line-height: 1;
}

.modal-body {
  padding: 20px;
  text-align: center;
}

.modal-text {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  border-top: 1px solid #f0f0f0;
}

.modal-btn {
  flex: 1;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s;
}

.cancel-btn {
  border-right: 1px solid #f0f0f0;
  
  &:active {
    background-color: #f5f5f5;
  }
}

.confirm-btn {
  background-color: #1296db;
  
  &:active {
    background-color: #0f7bb8;
  }
}

.btn-text {
  font-size: 16px;
  color: #333;
}

.confirm-btn .btn-text {
  color: white;
}
</style> 